// pages/movie/movie.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载 https://api.douban.com/v2/movie/in_theaters?start=0&count=3
   * 正在售票 inTheaters: https://api-m.mtime.cn/PageSubArea/HotPlayMovies.api?locationId=290
   * 正在热映 comingSoon: https://api-m.mtime.cn/Showtime/LocationMovies.api?locationId=290
   * 即将上映 top250: https://api-m.mtime.cn/Movie/MovieComingNew.api?locationId=290
   */
  onLoad: function (options) {
    var inTheatersUrl = app.globalData.g_douBanBase +
      "/PageSubArea/HotPlayMovies.api" + "?locationId=290";
    var comingSoonUrl = app.globalData.g_douBanBase +
      "/Showtime/LocationMovies.api" + "?locationId=290";
    var top250Url = app.globalData.g_douBanBase +
      "/Movie/MovieComingNew.api" + "?locationId=290";
    this.getData(inTheatersUrl, "inTheaters", "正在热映");
    this.getData(comingSoonUrl, "comingSoon", "即将上映");
    this.getData(top250Url, "top250", "top250");
  },

  getData: function (url, key, header) {
    var that = this;
    wx.request({
      url: url,
      method: 'GET',
      header: {
        'content-type': 'application/json',
      },
      success: function (res) {
        if (key == "inTheaters") {
          that.dealWithData(res.data.movies, key, header);
        } else if (key == "comingSoon") {
          that.dealWithData(res.data.ms, key, header);
        } else {
          that.dealWithData(res.data.moviecomings, key, header);
        }
      },
      fail: function (error) {
      }
    })
  },

  dealWithData: function (movies, key, header) {
    var firstData = {};
    firstData["movies"] = movies;
    firstData["header"] = header;

    var data1 = {};
    data1[key] = firstData;
    this.setData(data1);
  },

  clickMore: function (data) {
    console.log(data.currentTarget.dataset.type);
    wx.navigateTo({
      url: 'movie-more/movie-more',
    })
  },

  clickMovieDetail:function(data){

    console.log("clickMovieDetail    " + data.currentTarget.dataset.detail);
  }


})